package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Mapper
public interface UserMapper {
    /**
     * 根据openId查询用户是否存在
     * @param openId
     * @return
     */
    @Select("select * from user where openid = #{openId}")
    User selectUserByOpenId(String openId);

    /**
     * 创建新的微信用户，并回显用户的id
     * @param user
     * @return
     */
    Long insert(User user);

    /**
     * 根据userId查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User get(Long userId);

    /**
     * 获取当天的用户总数
     * @param date
     * @return
     */
    @Select("SELECT count(user.id) FROM user WHERE DATE(user.create_time) < #{date}")
    Integer selectTotalUser(LocalDate date);

    /**
     * 查找特定时间段的新用户
     * @param begin
     * @param end
     * @return
     */
    Integer selectNewUser(LocalDate begin, LocalDate end);
}
